{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 本代码用于验证是否每个需要预测的运单都有足够多的同路由数据\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "from tqdm import tqdm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "test_data_path = '../data/A_testData0531.csv'\n",
    "train_gps_path = '../data/train0523.csv'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_data_origin = pd.read_csv(test_data_path)\n",
    "test_trace_set = test_data_origin['TRANSPORT_TRACE'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "148it [06:39,  2.70s/it]"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'CNYTN-MXZLO': 415248, 'CNSHK-MYTPP': 0, 'CNSHK-SGSIN': 190832, 'CNSHK-CLVAP': 165070, 'CNYTN-ARENA': 262145, 'CNYTN-MATNG': 522061, 'CNSHK-GRPIR': 0, 'CNSHK-PKQCT': 108849, 'COBUN-HKHKG': 3375, 'CNYTN-PAONX': 330528, 'CNSHK-SIKOP': 88313, 'CNYTN-CAVAN': 146730, 'CNSHK-ESALG': 0, 'CNYTN-MTMLA': 10727, 'CNSHK-ZADUR': 2330352, 'CNSHK-LBBEY': 1700, 'CNSHA-SGSIN': 0, 'CNYTN-RTM': 116699, 'CNHKG-MXZLO': 377267, 'HKHKG-FRFOS': 0, 'CNYTN-NZAKL': 84240, 'CNSHA-PAMIT': 9034}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\n"
     ]
    }
   ],
   "source": [
    "trace_dict = {}\n",
    "for item in test_trace_set:\n",
    "    trace_dict[item] = 0\n",
    "train_data_origin_chunk = pd.read_csv(train_gps_path, chunksize = 1000000, usecols = [0, 12], header=None)\n",
    "\n",
    "for chunk in tqdm(train_data_origin_chunk):\n",
    "    valid_route = chunk[chunk[12].isin(test_trace_set)][12].unique()\n",
    "    for route in valid_route:\n",
    "        orders_match_route = chunk[chunk[12] == route][0].unique()\n",
    "        route_record_cnt = chunk[chunk[0].isin(orders_match_route)].shape[0]\n",
    "        trace_dict[route] = trace_dict[route] + route_record_cnt\n",
    "print (trace_dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.6 64-bit ('AI': conda)",
   "language": "python",
   "name": "python37664bitaiconda6859e03b37c34f0182c9bde8073269f7"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
